<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="origin-trial"
          content="AhQB+uNRI7lww30oPK+0ZcGotIvuoHJL+NkkWOhqDdooY6+xnuiYmZli2SwlH1vkrKdB5WxMpsv5KRc/q9zFswoAAAB3eyJvcmlnaW4iOiJodHRwczovL2plc3NpYnVjYS5jb206NDQzIiwiZmVhdHVyZSI6IlVucmVzdHJpY3RlZFNoYXJlZEFycmF5QnVmZmVyIiwiZXhwaXJ5IjoxNzA5ODU1OTk5LCJpc1N1YmRvbWFpbiI6dHJ1ZX0=">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Jessibuca Pro 点播 demo</title>
    <script src="./vconsole.js"></script>
    <script src="./js/jessibuca-pro-demo.js"></script>
    <link rel="stylesheet" href="./demo.css">
    <style>
        .container-shell:before {
            content: "jessibuca pro hls 点播 demo";
        }
    </style>
</head>
<body class="page">
<div class="root">
    <div class="container-shell">
        <div id="container"></div>
        <div class="input">
            <div>
                当前浏览器：
                <span id="mseSupport264" style="color: green;display: none">支持MSE H264解码；</span>
                <span id="mseSupport" style="color: green;display: none">支持MSE H265解码；</span>
                <span id="mseNotSupport264" style="color: red;display: none">不支持MSE H264解码；</span>
                <span id="mseNotSupport"
                      style="color: red;display: none">不支持MSE H265解码,会自动切换成wasm解码；</span>
            </div>
        </div>
        <div class="input">
            <div>
                当前浏览器：
                <span id="wcsSupport264" style="color: green;display: none">支持Webcodecs H264解码；</span>
                <span id="wcsSupport" style="color: green;display: none">支持Webcodecs H265解码（不一定准确）；</span>
                <span id="wcsNotSupport264"
                      style="color: red;display: none">不支持Webcodecs H264解码(https/localhost)；</span>
                <span id="wcsNotSupport" style="color: red;display: none">不支持Webcodecs H265解码(https/localhost),会自动切换成wasm解码</span>
            </div>
        </div>
        <div class="input">
            <div>
                当前浏览器：
                <span id="wasmSupport" style="color: green;display: none">支持WASM解码；</span>
                <span id="simdSupport" style="color: green;display: none">支持WASM SIMD解码；</span>
                <span id="simdMtSupport" style="color: green;display: none">支持WASM WASM(SIMD) 多线程解码；</span>
                <span id="wasmNotSupport" style="color: red;display: none">不支持WASM解码；</span>
                <span id="simdNotSupport"
                      style="color: red;display: none">不支持WASM SIMD解码,会自动切换成wasm解码；</span>
                <span id="simdMtNotSupport" style="color: red;display: none">不支持WASM WASM(SIMD) 多线程解码；</span>
            </div>
        </div>

        <div class="input">
            <div>
                <div>
                    <span>硬解码：</span>
                    <input
                        type="checkbox"
                        checked
                        id="useMSE"
                    /><span>MediaSource</span>
                    <input
                        type="checkbox"
                        id="useWCS"
                    /><span>Webcodec</span>
                </div>
                <div>
                  <span>软解码：</span>
                    <input
                        type="checkbox"
                        id="useWASM"
                    /><span>WASM</span>
                    <input
                        type="checkbox"
                        id="useSIMD"
                    /><span>WASM(SIMD)</span>
                    <input
                        type="checkbox",
                        id="isFFmpegSIMD"
                        onclick="replay()"
                    /><span>isSIMD(V2)</span>
                    <input
                        type="checkbox"
                        checked
                        id="useSIMDMThreading"
                        onclick="replay()"
                    /><span>启动多线程（WASM,WASM(SIMD)解码支持）</span>
                    <span style="color: green">默认使用wasm解码器</span>
                </div>
            </div>
        </div>

        <div class="input">
            <div>
                <input
                    checked
                    onclick="replay()"
                    type="checkbox"
                    id="isHls"
                /><span>强制HLS</span>
                <button onclick="replay()">重播</button>
            </div>
        </div>
        <div class="input">
            <div>
                <div>
                    <span style="color: red">H264:</span>https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8
                </div>
                <div>
                    <span style="color: red">H264:</span>https://vod.lyhuicheng.com/20230719/oc5MCoON/index.m3u8
                </div>
                <div>
                    <span style="color: red">H265:</span>
                    <span style="word-break: break-all">https://voddemo-play.volcvod.com/8d1417d814b24fee8b8b0c2747f303e5/main.m3u8?a=0&auth_key=1765632280-d3569ddc77d445ab8647746220f67766-0-0222f8289976f07f8c91c230753ce911&br=384&bt=384&cd=0%7C0%7C0&ch=0&cr=1&cs=&cv=1&dr=0&ds=2&er=0&l=202212142122085BF19BF20712C413A9A2&lr=&mime_type=video_mp4&net=0&pl=0&qs=0&rc=amg6c2o0aTg6ZTQzNGRnM0ApZzlnZzNlPGRlNzZmZTg5NWdfZy9gMHFrYTBgLS1kYy9zczQxNi4wYmItLTVgYTFjXjU6Yw%3D%3D&vl=&vr=</span>

                </div>
            </div>
        </div>
        <div class="input">
            <div>输入URL：</div>
            <input
                autocomplete="on"
                id="playUrl"
                value="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8"
            />
        </div>
        <div class="input">
            <button id="play">播放</button>
            <button id="playVodPause">停止</button>
        </div>
        <div class="input">
            <button id="playVodForward">快进10s</button>
            <button id="playVodBackword">快退10s</button>
            <select id="forward" onchange="changeForward()">
                <option value="1" selected>1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
                <option value="13">13</option>
                <option value="14">14</option>
                <option value="15">15</option>
                <option value="16">16</option>
            </select>
            <button onclick="getPlayVodIsPause()">当前状态</button>
        </div>
        <div class="input" style="line-height: 30px">
            <button id="destroy">销毁</button>
        </div>
    </div>
</div>
<script src="./demo.js"></script>

<script>
    var $player = document.getElementById('play');
    var $playVodPause = document.getElementById('playVodPause');
    var $playHref = document.getElementById('playUrl');
    var $container = document.getElementById('container');
    var $destroy = document.getElementById('destroy');
    var $useMSE = document.getElementById('useMSE');
    var $useSIMD = document.getElementById('useSIMD');
    var $isFFmpegSIMD = document.getElementById('isFFmpegSIMD');
    var $useWCS = document.getElementById('useWCS');
    var $useWASM = document.getElementById('useWASM');
    var $playVodForward = document.getElementById('playVodForward');
    var $playVodBackword = document.getElementById('playVodBackword');
    var $isHls = document.getElementById('isHls');
    var $useSIMDMThreading = document.getElementById('useSIMDMThreading');


    var forceNoOffscreen = true; //
    var jessibuca = null;
    var isPlayVodPause = false;


    function create() {
        const showOperateBtns = true;
        jessibuca = new JessibucaPro({
            playType: 'playVod',
            container: $container,
            videoBuffer: 0.2, // 缓存时长
            decoder: './js/decoder-pro.js',
            isResize: false,
            text: "",
            loadingText: "加载中",
            debug: true,
            debugLevel: 'debug',
            isFFmpegSIMD: $isFFmpegSIMD.checked === true,
            useMThreading: $useSIMDMThreading.checked === true,
            decoderErrorAutoWasm: false,
            timeout: 10000,
            // showPerformance: true,
            showBandwidth: showOperateBtns, // 显示网速
            showPlaybackOperate: showOperateBtns,
            operateBtns: {
                fullscreen: showOperateBtns,
                screenshot: showOperateBtns,
                play: showOperateBtns,
                audio: showOperateBtns,
                performance: showOperateBtns,
            },
            playVodConfig: {
                showRateBtn: true,
                rateConfig: [
                    {label: '正常', value: 1},
                    {label: '2倍', value: 2},
                    {label: '3倍', value: 3},
                    {label: '4倍', value: 4},
                    {label: '5倍', value: 5},
                    {label: '6倍', value: 6},
                    {label: '7倍', value: 7},
                    {label: '8倍', value: 8},
                    {label: '9倍', value: 9},
                    {label: '10倍', value: 10},
                    {label: '11倍', value: 11},
                    {label: '12倍', value: 12},
                    {label: '13倍', value: 13},
                    {label: '14倍', value: 14},
                    {label: '15倍', value: 15},
                    {label: '16倍', value: 16},
                ],
                useWCS: $useWCS.checked,
                useMSE: $useMSE.checked,
                useSIMD: $useSIMD.checked,
            },
            forceNoOffscreen: forceNoOffscreen,
            muted: false,
            isHls: $isHls.checked,
        },);

        jessibuca.on('playVodEnded', function () {
            console.log('playVodEnded');
        })

        jessibuca.on('playVodRateChange', function (rate) {
            console.log('playVodRateChange', rate);
        })

        $player.style.display = 'inline-block';
        $playVodPause.style.display = 'none';
        $destroy.style.display = 'none';
    }


    create();

    function replay() {
        if (jessibuca) {
            jessibuca.destroy().then(() => {
                create();
                play();
            });
        } else {
            create();
            play();
        }
    }

    function play() {
        var href = $playHref.value;

        if (!href) {
            return
        }

        if (isPlayVodPause) {
            jessibuca.playVodResume()
        } else {
            jessibuca.playVod(href).then(() => {
                notifySuccess('播放成功');
            }).catch((error) => {
                jessibuca.showErrorMessageTips(error.toString());
            });
        }
        isPlayVodPause = false;
        $player.style.display = 'none';
        $playVodPause.style.display = 'inline-block';
        $destroy.style.display = 'inline-block';
    }


    $player.addEventListener('click', function () {
        play();
    }, false)


    $useMSE.addEventListener('click', function () {
        const checked = $useMSE.checked;
        if (checked) {
            $useSIMD.checked = false
            $useWCS.checked = false
            $useWASM.checked = false
        }
        replay();
    })

    $useSIMD.addEventListener('click', function () {
        const checked = $useSIMD.checked;
        if (checked) {
            $useMSE.checked = false
            $useWCS.checked = false
            $useWASM.checked = false

        }
        replay();
    })

    $useWCS.addEventListener('click', function () {
        const checked = $useWCS.checked;
        if (checked) {
            $useMSE.checked = false
            $useSIMD.checked = false
            $useWASM.checked = false
        }
        replay();
    })

    $useWASM.addEventListener('click', function () {
        const checked = $useWASM.checked;
        if (checked) {
            $useMSE.checked = false
            $useSIMD.checked = false
            $useWCS.checked = false
        }
        replay();
    })

    $isHls.addEventListener('click', function () {
        replay();
    })


    $playVodPause.addEventListener('click', function () {
        $playVodPause.style.display = 'none';
        $player.style.display = 'inline-block';
        jessibuca.playVodPause();
        isPlayVodPause = true;
    })

    $destroy.addEventListener('click', function () {
        if (jessibuca) {
            jessibuca.destroy().then(() => {
                create();
            });
        } else {
            create();
        }

    })

    $playVodForward.addEventListener('click', function () {
        if (jessibuca) {
            jessibuca.playVodForwardJumping(10);
        }
    })

    $playVodBackword.addEventListener('click', function () {
        if (jessibuca) {
            jessibuca.playVodBackwordJumping(10);
        }
    })

    function getPlayVodIsPause() {
        if (jessibuca) {
            console.log('getPlayVodIsPause', jessibuca.isPlayVodPaused());
        }
    }

    function changeForward() {
        const forward = document.getElementById('forward').value;
        if (jessibuca) {
            jessibuca.playVodForward(forward);
        }
    }


</script>

</body>
</html>
